package com.txc.pay.pay.impl;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.txc.pay.entity.AccountEntity;
import com.txc.pay.pay.ThirdPay;
import com.txc.pay.vo.OrderVo;
import org.springframework.stereotype.Service;



/**
 * @ClassName: AliPay
 * @Description: 支付宝支付
 * @Author: TXC
 * @Date: 2023-12-25 10:56
 **/
@Service
public class AliNativePay extends AliPay implements ThirdPay {

    @Override
    public String pay(OrderVo order) {
        aliConfig(order.getAccountId());
        AlipayTradePrecreateResponse response;
        try {
            AccountEntity account = getAccount(order.getAccountId());
            response = Factory.Payment.FaceToFace().asyncNotify(aliPayConfig(account).getNotifyUrl())
                    .preCreate(order.getTitle(), order.getId(), order.getPriceYuan());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        return response.getQrCode();
    }


}
